﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace OnlineFamilyCalendar.Common.Configuration
{
    public class OnlineFamilyCalendarAuthenticationSection : ConfigurationSection
    {
        private static readonly ConfigurationProperty _loginUrl;
        private static readonly ConfigurationProperty _registerUrl;
        private static readonly ConfigurationProperty _cookieName;
        private static readonly ConfigurationProperty _cookieExpiration;
        private static readonly ConfigurationProperty _redirectUrl;

        static OnlineFamilyCalendarAuthenticationSection()
        {
            _loginUrl = new ConfigurationProperty("loginUrl", typeof(string), "Login.aspx",
                null, null, ConfigurationPropertyOptions.IsRequired);

            _registerUrl = new ConfigurationProperty("registerUrl", typeof(string), "Register.aspx",
                null, null, ConfigurationPropertyOptions.IsRequired);

            _cookieName = new ConfigurationProperty("cookieName", typeof(string), "OnlineFamilyCalendarAuth",
                null, null, ConfigurationPropertyOptions.IsRequired);

            _cookieExpiration = new ConfigurationProperty("cookieExpiration", typeof(int), 20,
                null, null, ConfigurationPropertyOptions.IsRequired);

            _redirectUrl = new ConfigurationProperty("redirectUrl", typeof(string), "Calendar.aspx",
                null, null, ConfigurationPropertyOptions.IsRequired);
        }

        public OnlineFamilyCalendarAuthenticationSection() : base()
        {
            this.Properties.Add(_loginUrl);
            this.Properties.Add(_registerUrl);
            this.Properties.Add(_cookieName);
            this.Properties.Add(_cookieExpiration);
            this.Properties.Add(_redirectUrl);
        }

        public string LoginUrl
        {
            get { return this["loginUrl"] as string; }
        }

        public string RegisterUrl
        {
            get { return this["registerUrl"] as string; }
        }

        public string CookieName
        {
            get { return this["cookieName"] as string; }
        }

        public int CookieExpiration
        {
            get { return (int) this["cookieExpiration"]; }
        }

        public string RedirectUrl
        {
            get { return this["redirectUrl"] as string; }
        }
    }
}
